<?php
/**
 * Created by PhpStorm.
 * User: zy
 * Date: 15/12/14
 * Time: 下午5:40
 */

$date = date("Y-m-d H:i:s");
$s = $_SERVER["HTTP_USER_AGENT"];
file_put_contents("userdata.txt", "{$date} - "  .getIP() . " - {$s}\r\n", FILE_APPEND);
echo "ok";

function getIP() {
    if (getenv('HTTP_CLIENT_IP')) {
        $ip = getenv('HTTP_CLIENT_IP');
    }
    elseif (getenv('HTTP_X_FORWARDED_FOR')) {
        $ip = getenv('HTTP_X_FORWARDED_FOR');
    }
    elseif (getenv('HTTP_X_FORWARDED')) {
        $ip = getenv('HTTP_X_FORWARDED');
    }
    elseif (getenv('HTTP_FORWARDED_FOR')) {
        $ip = getenv('HTTP_FORWARDED_FOR');

    }
    elseif (getenv('HTTP_FORWARDED')) {
        $ip = getenv('HTTP_FORWARDED');
    }
    else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}